
class Person(object):

    def __init__(self,name,age):
        self.name = name
        self.age  = age

    def walk(self):
        print("walking...")


def talk(self):
    print(self.name,"is talking...")


p = Person("Alex",22)
if hasattr(p,"name"): # 映射
    print("yes")

# 反射、映射、自省

# # getattr() # get 获取
# a = getattr(p,"age")
# print(a)
#
# # hasattr() # 判断是否含有
# user_command = input(">>:").strip()
# if hasattr(p,user_command):
#     func = getattr(p,user_command)
#     func()
#
# # setattr() # 赋值
# ## 属性 静态
# setattr(p,"sex","Female")
# print(p.sex)
#
# ## 方法 静态
# # setattr(p,"speak",talk) # 给实例加的方法
# # p.speak(p)
#
# ## 方法 动态
# setattr(Person,"speak2",talk)
# p.speak2()
#
#
#
# # delattr() # 删除
# # delattr(p,"age") # 等同于 del p.age
# # p.age

print(__name__) # __main__  就代表模块本身，self.

if __name__ == "__main__": # ='__main__'说明不是被导入，自己主动执行 ｜｜ 只会在被别的模块导入的时候发生作用
    print("hahahaha")

import sys

# for k,v in sys.modules.items():
#     print(k,v)

print(sys.modules["__main__"])
print(sys.modules[__name__])

mod = sys.modules[__name__]
if hasattr(mod,"p"):
    o = getattr(mod,"p")
    print(o)
print(p)